#!/local/python36/bin python3
__author__ = '无崖子'
import os
import logging.handlers
import datetime

logger = logging.getLogger('mylogger')
logger.setLevel(logging.DEBUG)
# 是否存在logs文件
if not os.path.exists('logs'):
    os.makedirs('logs')
# 所有日志
af_handler = logging.handlers.TimedRotatingFileHandler('logs/all.log', when='midnight', interval=1, backupCount=30,
                                                       atTime=datetime.time(0, 0, 0, 0), encoding="UTF-8")
af_handler.suffix = "%Y-%m-%d_%H-%M-%S.log"  # 分割文件的格式
af_handler.setFormatter(logging.Formatter(fmt="%(levelname)s %(asctime)s line:%(lineno)d %(pathname)s: %(message)s",
                                          datefmt='%Y-%m-%d %H:%M:%S'))

# 错误日志
ef_handler = logging.FileHandler('logs/error.log', encoding="UTF-8")
ef_handler.setLevel(logging.ERROR)
ef_handler.setFormatter(logging.Formatter(fmt="%(levelname)s %(asctime)s line:%(lineno)d %(pathname)s: %(message)s",
                                          datefmt='%Y-%m-%d %H:%M:%S'))

ef_handler = logging.FileHandler('logs/address.log', encoding="UTF-8")
ef_handler.setLevel(logging.CRITICAL)
ef_handler.setFormatter(logging.Formatter(fmt="%(levelname)s %(asctime)s : %(message)s", datefmt='%Y-%m-%d %H:%M:%S'))

logger.addHandler(af_handler)
logger.addHandler(ef_handler)
